//
//  OYCUserAccount.swift
//  WeiBo-Swift
//
//  Created by daniel on 2017/8/6.
//  Copyright © 2017年 daniel. All rights reserved.
//

import UIKit

class OYCUserAccount: NSObject, NSCoding {
    
    var access_token: String?
    var expires_in: TimeInterval = 0 {
        didSet {
            expires_date = NSDate.init(timeIntervalSinceNow: expires_in)
        }
    }
    var expires_date: NSDate?
    
    var uid: String?
    
    /// 用户昵称
    var screen_name: String?
    /// 用户头像地址（大图），180×180像素
    var avatar_large: String?
    
    init(dic: [String : Any]) {
        super.init()
        
        setValuesForKeys(dic)
    }
    
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(uid, forKey: "uid")
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init()
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as? NSDate
        uid = aDecoder.decodeObject(forKey: "uid") as? String
    }
    
    
    override var description: String {
        
        let keys = ["access_token" , "expires_in", "expires_date","uid", "screen_name", "avatar_large"]
        return dictionaryWithValues(forKeys: keys).description
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
    
    
}
